package website.seamonster.ethegg.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import website.seamonster.ethegg.dataobject.Egg;
import website.seamonster.ethegg.enums.EggStatusEnum;
import website.seamonster.ethegg.repository.EggRepository;

/**
 * Created by 罗海量
 * 2018-07-21 21:50
 */
@lombok.extern.slf4j.Slf4j
@Service
public class SellingBatchNoService {
    @Autowired
    private EggRepository eggRepository;

    /**
     * 获取"出售中"的蛋的批次
     * @return
     */
    public int getSellingBatchNo(){
        Egg egg = eggRepository.findFirstByEggStatus(EggStatusEnum.SALE.getCode());
        if (egg == null) {
            egg = eggRepository.findFirstByEggStatus(EggStatusEnum.PRE.getCode());
        }
        return egg.getBatchNum();
    }


}
